//
//  CoreDataManager.h
//  ErJie
//
//  Created by yaorenjin on 2017/1/30.
//  Copyright © 2017年 yaorenjin. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
#import "ShangPinFenLeiEntity+CoreDataProperties.h"
#import "ShangPinEntity+CoreDataProperties.h"
#import "ZhangDanEntity+CoreDataProperties.h"
#import "ZhangDanShangPinRelationEntity+CoreDataProperties.h"
#import "KeHuEntity+CoreDataProperties.h"
#import "ShangPinModel.h"   
#import "TimeTool.h"    
#import "ShangPinFenLeiModel.h"
#import "ZhangDanModel.h"   
#import "ZhangDanShangPinRelationModel.h"   
#import "KeHuModel.h"

@interface CoreDataManager : NSObject
@property(nonatomic,strong)NSManagedObjectModel* managedObjectModel;
+(CoreDataManager*)shareManager;
- (NSManagedObjectContext *)managedObjectContext;
- (void)saveContext;
//创建客户
-(KeHuEntity*)createKeHuEntity;
//插入客户
-(BOOL)insertKeHu:(KeHuEntity*)khEntity;
//删除客户
-(BOOL)deleteKeHu:(KeHuEntity*)khEntity;
//更新客户
-(BOOL)updateKeHu:(KeHuEntity*)khEntity;
//查询客户
-(NSMutableArray<KeHuEntity*>*)selectKeHu;
//获取kid
-(NSString*)getKid;
//创建客户
-(KeHuModel*)createKeHuModel;
//转实体
-(KeHuModel*)toKeHuModel:(KeHuEntity*)spEntity;
//转实体
-(KeHuEntity*)toKeHuEntity:(KeHuModel*)model;


//创建商品
-(ShangPinEntity*)createShangPinEntity;
//插入商品
-(BOOL)insertShangPin:(ShangPinEntity*)spEntity;
//删除商品
-(BOOL)deleteShangPin:(ShangPinEntity*)spEntity;
//更新商品
-(BOOL)updateShangPin:(ShangPinEntity*)spEntity;
//查询商品
-(NSMutableArray<ShangPinEntity*>*)selectShangPin;
//获取sid
-(NSString*)getSid;
//转换对象
-(ShangPinModel*)toShangPinModel:(ShangPinEntity*)spEntity;
//查询商品
-(NSMutableArray<ShangPinEntity*>*)selectShangPinWithIds:(NSString*)ids;
//查询商品
-(NSMutableArray<ShangPinEntity*>*)selectShangPinWithFlId:(NSInteger)flId;
//创建商品
-(ShangPinModel*)createShangPinModel;
//商品实体
-(ShangPinEntity*)toShangPinEntity:(ShangPinModel*)model;
//更新库存
-(BOOL)updateShangPinId:(NSString*)fId kunCunCount:(NSInteger)count;


//创建商品分类
-(ShangPinFenLeiEntity*)createShangPinFenLeiEntity;
//插入商品分类
-(BOOL)insertShangPinFenLei:(ShangPinFenLeiEntity*)spEntity;
//删除商品分类
-(BOOL)deleteShangPinFenLei:(ShangPinFenLeiEntity*)spEntity;
//更新商品分类
-(BOOL)updateShangPinFenLei:(ShangPinFenLeiEntity*)spEntity;
//查询商品分类
-(NSMutableArray<ShangPinFenLeiEntity*>*)selectShangPinFenLei;
//查询今日商品分类 销售排行
-(NSMutableArray<ShangPinFenLeiModel*>*)selectSaleMoreWithToday;
//查询本周商品分类 销售排行
-(NSMutableArray<ShangPinFenLeiModel*>*)selectSaleMoreWithWeek;
//查询本周商品分类 销售排行
-(NSMutableArray<ShangPinFenLeiModel*>*)selectSaleMoreWithMonth;
//查询本周商品分类 销售排行
-(NSMutableArray<ShangPinFenLeiModel*>*)selectSaleMoreWithYear;
//查询今日商品分类 库存排行
-(NSMutableArray<ShangPinFenLeiEntity*>*)selectKunCunWithToday;
//转换对象
-(ShangPinFenLeiModel*)toShangPinFenLeiModel:(ShangPinFenLeiEntity*)spEntity;
//创建商品
-(ShangPinFenLeiModel*)createShangPinFenLeiModel;
//商品实体
-(ShangPinFenLeiEntity*)toShangPinFenLeiEntity:(ShangPinFenLeiModel*)model;
//更新库存
-(BOOL)updateShangPinFenLeiId:(NSString*)fId kunCunCount:(NSInteger)count;
//获取Fid
-(NSString*)getFid;


//创建账单
-(ZhangDanEntity*)createZhangDanEntity;
//插入账单
-(BOOL)insertZhangDan:(ZhangDanEntity*)zdEntity isHaveIds:(BOOL)isHaveIdsBool;
//删除账单
-(BOOL)deleteZhangDan:(ZhangDanEntity*)zdEntity;
//更新账单
-(BOOL)updateZhangDanIsPayWithZid:(NSInteger)zId;
//查询账单
-(NSMutableArray<ZhangDanEntity*>*)selectZhangDan;
//查询今日商品分类 销售排行
-(NSMutableArray<ZhangDanEntity*>*)selectZhangDanWithToday;
//查询本周商品分类 销售排行
-(NSMutableArray<ZhangDanEntity*>*)selectZhangDanWithWeek;
//查询本月商品分类 销售排行
-(NSMutableArray<ZhangDanEntity*>*)selectZhangDanWithMonth;
//查询本年商品分类 销售排行
-(NSMutableArray<ZhangDanEntity*>*)selectZhangDanWithYear;
//查询欠账
-(NSMutableArray<ZhangDanEntity*>*)selectQianKuanZhangDan;
//获取Zid
-(NSString*)getZid;
//账单实体
-(ZhangDanModel*)toZhangDanModel:(ZhangDanEntity*)entity;
//账单实体
-(ZhangDanEntity*)toZhangDanEntity:(ZhangDanModel*)model;
//创建实体
-(ZhangDanModel*)createZhangDanModel;


//创建账单和商品的关联表
-(ZhangDanShangPinRelationEntity*)createZhangDanShangPinRelationEntity;
//插入关联表
-(BOOL)insertZhangDanShangPinRelation:(ZhangDanShangPinRelationEntity*)glEntity isHaveIds:(BOOL)isHaveIdsBool;
//删除关联表
-(BOOL)deleteZhangDanShangPinRelation:(ZhangDanShangPinRelationEntity*)zdEntity;
//更新关联表
-(BOOL)updateZhangDanShangPinRelation:(ZhangDanShangPinRelationEntity*)zdEntity;
//查询关联表
-(NSMutableArray<ZhangDanShangPinRelationEntity*>*)selectZhangDanShangPinRelation;
//查询关联表
-(NSMutableArray<ZhangDanShangPinRelationEntity*>*)selectZhangDanShangPinRelationWithIds:(NSString*)ids;
//获取账单和商品的关联id
-(NSString*)getZdsprId;
//获取账单和商品的关联id
-(void)setZdsprId:(NSInteger)zdsprId;

//实体
-(ZhangDanShangPinRelationModel*)toZhangDanShangPinRelationModel:(ZhangDanShangPinRelationEntity*)entity;
//账单实体
-(ZhangDanShangPinRelationEntity*)toZhangDanShangPinRelationEntity:(ZhangDanShangPinRelationModel*)model;
//创建实体
-(ZhangDanShangPinRelationModel*)createZhangDanShangPinRelationModel;


@end
